import { mapGetters, mapMutations, mapActions } from 'vuex'
const appMixin = {
	computed: {
		...mapGetters({
			getAdult: 'app/getAdult',
			getAdultPwd: 'app/getAdultPwd',
			skinMode: 'app/skinMode',
			skinColor: 'app/skinColor'
		}),
		app () {
			return getApp().globalData
		},
		bottomPopupHeight () {
			return this.windowHeight * (2 / 3)
		}
	},
	data () {
		return {
			windowWidth: 0,
			windowHeight: 0
		}
	},
	created () {
		this.windowWidth = uni.getSystemInfoSync().windowWidth
		this.windowHeight = uni.getSystemInfoSync().windowHeight
	},
	methods: {
		...mapMutations({
			setAdult: 'app/setAdult',
			setAdultPwd: 'app/setAdultPwd'
		}),
		...mapActions({
			changeSkin: 'app/switchSkin'
		}),
		isBack () {
			this.$refs.dialog.confirm({
				title: {
					color: this.skinColor.color_1,
					text: '退出提示'
				},
				content: {
					text: '要退出应用吗？再次点击返回键取消',
					color: this.skinColor.color_2
				},
				confirm: "后台运行",
				cancel: "直接退出",
				options: {
					bgColor: this.skinColor.color_bg_2,
					type: 3
				},
				success: (res) => {
					getApp().globalData.backTime = 0
					if ( res.confirm ) {
						plus.android.runtimeMainActivity().moveTaskToBack(false);
					} else {
						getApp().globalData.backTime = 2
						plus.runtime.quit()
					}
				},
				fail: () => {
					getApp().globalData.backTime = 0
				}
			})
		}
	}
}

export default appMixin;